<?php

class Database {

	static $instance = null;

	private function __construct()
	{
		$host = $GLOBALS['CFG']->config['database']['host'];
		$user = $GLOBALS['CFG']->config['database']['user'];
		$pass = $GLOBALS['CFG']->config['database']['pass'];
		$base = $GLOBALS['CFG']->config['database']['base'];

		try
		{
			self::$instance = new mysqli($host, $user, $pass, $base);
		}
		catch ( Exception $e )
		{
			echo "Falha ao conectar com o banco!";
		}
	}

	public static function getInstance()
	{
		if ( self::$instance == null )
			new Database();
		return self::$instance;
	}

	public static function close()
	{
		self::$instance = null;
	}

}

?>